package com.geyue.core.service.impl;

import com.geyue.common.base.service.impl.BaseServiceImpl;
import com.geyue.common.toolbox.result.Res;
import com.geyue.core.mapper.TeacherMapper;
import com.geyue.core.model.Teacher;
import com.geyue.core.model.Vedio;
import com.geyue.core.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Lyon on 2017/3/27.
 */
@Service
public class TeacherServiceImpl extends BaseServiceImpl<Teacher> implements TeacherService {

    @Autowired
    private TeacherMapper teacherMapper;

    @Override
    public Res pay(Integer id, Integer money) {

        Teacher teacher = teacherMapper.selectByPrimaryKey(id);

        if(teacher.getMoney() < money)
            return Res.fail("当前用户学习币不足!");

        if(teacherMapper.pay(id,money) > 0)
            return  Res.success("结算成功!");

        return Res.fail("结算失败!");
    }

    @Override
    public List<Teacher> getTopList() {
        return teacherMapper.getTopList();
    }

    @Override
    public List<Teacher> searchTeacher(String keyword) {

        return teacherMapper.searchTeacher(keyword);
    }
}
